home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Tele / C / Comet2.1.3.cpt / 3270XCMD / TNReceive.c < prev    next >
Text File  |  1990-05-23  |  4KB  |  166 lines

  1. /* TNReceive.c -- XCMD copy 3270 screen into a global 
  2.     copyright 1989 Cornell University 
  3. */
  4.  
  5.  
  6. #include <Types.h>
  7. #include <Memory.h>
  8. #include <Devices.h>
  9. #include <HyperXCmd.h>
  10. #include <Errors.h>
  11.  
  12. #include <OSUtils.h>
  13.  
  14. #include <String.h>
  15.  
  16. #include "TNdrvr.h"
  17.  
  18.  
  19. pascal void debugger()    extern 0xA9FF;   
  20.  
  21. extern long mystrtolong();
  22.  
  23. pascal void TNReceive(hycp)
  24. XCmdPtr hycp;
  25. {
  26.     CntrlParam drvpb;
  27.     long * args;
  28.     Str255 pstr;
  29.     char * bufptr;
  30.     Handle strhand;
  31.     int length;
  32.     
  33.     if (hycp->paramCount != 2) {
  34.         sethand(&hycp->returnValue, "TNReceive TNscreen,aglobal: need 2 arguments, aglobal quoted");
  35.         return;
  36.     }
  37.     
  38.     /* reformat buf ptr from string to ptr */
  39. #ifdef HYPE
  40.     /* HyperCard 1.2.5 StrToLong no longer works here! */
  41.     HLock((Handle) hycp->params[0]);
  42.     ZeroToPas(hycp, *hycp->params[0], (StringPtr) &pstr[0]);
  43.     HUnlock((Handle) hycp->params[0]);
  44.     
  45.     bufptr = (char *) StrToLong(hycp, (Str31 *) &pstr[0]);
  46. #else
  47.     bufptr = (char *) mystrtolong(*hycp->params[0]);
  48. #endif
  49.  
  50.     /* dump whole screen buffer into a handle */
  51.     if ((strhand = NewHandle((Size) HTNI_BUFSIZE)) == (Handle) 0L) {
  52.         sethand(&hycp->returnValue, "Out of memory");
  53.         return;
  54.     }
  55.     HLock(strhand);
  56.     length = screendump(bufptr, bufptr, *strhand, 1920);
  57.     HUnlock(strhand);
  58.     
  59.     *( ((char *) * strhand) + length) = 0;        /* terminate with a null */
  60.     
  61.     /* set the global given as an arg to the handle's contents */
  62.     HLock((Handle) hycp->params[1]);
  63.     ZeroToPas(hycp, (char *) *hycp->params[1], &pstr[0]);
  64.     HUnlock((Handle) hycp->params[1]);
  65.  
  66.  
  67.     SetGlobal(hycp, &pstr[0], strhand);
  68.     DisposHandle(strhand);
  69.  
  70.     if (hycp->result) {
  71.         sethand(&hycp->returnValue, "Can't set aglobal");
  72.         return;
  73.     }
  74. }
  75.  
  76.  
  77. /*    copy whole screen from scr_map format into a buffer, returning count copied 
  78.     target buffer must have (SCREEN_SIZE + COL_SIZE) bytes minimum
  79.     includes all spaces 
  80. */
  81.  
  82. screendump(bufp, screenp, destarr, count)
  83. unsigned char * bufp;        /* points at beginning of scr_map */
  84. unsigned char * screenp;    /* points into scr_map to read from */
  85. unsigned char * destarr;    /* points to dest to write into */
  86. int count;                    /* scrp + count -> last char to copy, exclusive */
  87. {
  88.     register unsigned char * srcp = screenp;
  89.     register unsigned char * destp = destarr;
  90.     register unsigned char * endp = screenp + count;    /* stake out the excluded end */
  91.     register unsigned char thechar;
  92.     unsigned char * lineend;                        /* really beginning of next line */
  93.     register int skiponzero;            /* # of good chars left in line */
  94.     int firsttime = true;                /* skip CR first time through loop */
  95.     
  96.     /* set up the skiponzero var for entry into the loop */
  97.     lineend = bufp + ((((srcp - bufp) / ROW_SIZE)) * ROW_SIZE);
  98.         /* set up lineend, which will point to beginning of next line */
  99.     skiponzero = 1;
  100.     
  101.     while (true) {
  102.         if (--skiponzero == 0) {
  103.             if (firsttime)
  104.                 firsttime = false;
  105.             else {
  106.                 *destp++ = CR;                            /* insert a CR for line end */
  107.                 srcp = lineend;                            /* set srcp forward */
  108.                 if (srcp >= endp)
  109.                     /* quit when we've done the work */
  110.                     break;
  111.             }
  112.             
  113.             lineend += ROW_SIZE;
  114.  
  115.             skiponzero = ROW_SIZE;
  116.         }
  117.         if (srcp >= endp)
  118.             /* quit when we've done the work */
  119.             break;
  120.  
  121.         /* copy */
  122.         if (((thechar = *srcp++) == (unsigned char) 0xFF) || (thechar < ATTR))
  123.             /* use space for nulls and attributes */
  124.             *destp++ = ' ';
  125.         else
  126.             *destp++ = thechar;
  127.     }
  128.     return(destp - destarr);        /* return length */
  129. }
  130.  
  131. sethand(thand, str)
  132. Handle * thand;
  133. char * str;
  134. {
  135.     if (*thand == NULL) {
  136.         *thand = NewHandle((Size) 0);
  137.     }
  138.     SetHandleSize(*thand, (long) (strlen(str) + 1));
  139.     strcpy(**thand, str);
  140. }
  141.  
  142.  
  143. long mystrtolong(strp)
  144. unsigned char * strp;
  145. {
  146.     long retval;
  147.     char negate = 0;
  148.     
  149.     retval = 0;
  150.     if (*strp == '-') {
  151.         negate = 1;
  152.         strp++;
  153.     }
  154.     while (*strp) {
  155.         retval = (long) (retval * 10) + (long) (*strp - '0');
  156.         strp++;
  157.     }
  158.     if (negate)
  159.         retval = (long) -retval;
  160.     return(retval);
  161. }
  162.  
  163.  
  164.  
  165.  
  166. #include <XCmdGlue.inc.c>